<html> 
 <head> 
  <script>
 
   function AddListeners (){     
     var elemToCheck = document.getElementById("myDiv");
    // Firefox和Chrome早期版本中带有前缀
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
        // 选择目标节点
        var target =elemToCheck; 
        // 创建观察者对象
        var observer = new MutationObserver(OnAttrModified); 
        // 配置观察选项:
        var config = { attributes: true, childList: false, characterData: false,attributeFilter:["ddd","aaa"]} 
        // 传入目标节点和观察选项
        observer.observe(target, config); 
        //停止观察
        // observer.disconnect();
   }  
      
   function OnAttrModified (event) {  
     console.log(event);
       
    }  
      
    function ChangeDDD () {  
       var div = document.getElementById ("myDiv");
       var nv=Math.random()+"";
       div.setAttribute("ddd",nv);
    }  
  </script> 
 </head> 
<body onload="AddListeners();"> 
  <button onclick="ChangeDDD();">Change ddd Attribute!</button> 
  <div id="myDiv" ddd="Old Attribute"> 
    divdivdivdivdivdivdivdiv 
  </div> 
</body> 
</html> 